import { JSONMapping } from "../../json-mapping";
import { InspectionRecords } from "./inspection-records";
import { InspectionOperationsTickets } from "./inspection-operation-tickets";
import { InspectionManuals } from "./inspection-manuals";
import {ObjectDtoInterface} from "../../../services/sqliteDB/object.dto";
import {SyncStatus} from "../../sync-status";
import { WorkTicket } from "./work-ticket";

export class InspectionTasks extends JSONMapping implements ObjectDtoInterface {
    static PropertyKeyToJSONKeyMap() {
        return {
            id: "planId",
            taskNo: "planCode",
            content: "jobContent",
            plannedDate: "planStartTime",
            attachmentIdForWorkTicket: "attachmentId",
            twoTicketsCreatedTime: "twoTicketsSubmitTime",
            inspectionRecordsSubmittedTime: "exploreSubmitTime",
            finishedTime: "overhaulSubmitTime",
            status: "exploreStatus",
            record: "exploration",
            operationsTicket: 'operation',
            manuals: 'instruction',
            workTicket: 'workTicket'
        };
    }

    static JSONValueTranslator(propertyKey) {
        if (propertyKey === "record") {
          return (jsonObj: object) => {
            return jsonObj ? new InspectionRecords(jsonObj) : null;
          };
        } else if (propertyKey === "operationsTicket") {
            return (jsonObj: object) => {
                return jsonObj ? new InspectionOperationsTickets(jsonObj) : null;
            };
        } else if (propertyKey === "manuals") {
            return (manualsJsonObjs: Array<object>) => {
                return manualsJsonObjs ? manualsJsonObjs.map((manualsJson) => new InspectionManuals(manualsJson)) : null;
            };
        } else if (propertyKey === "workTicket") {
            return (jsonObj: object) => {
                return jsonObj ? new WorkTicket(jsonObj) : null;
            };
        }


        return null;
      }

    public id: string = null; // 索引列
    public taskNo: string = null; // 检修任务编号
    public content: string = null; // 任务内容
    public plannedDate: number = null; // 计划检修的日期
    public pathForWorkTicket: string = null; // 工作票的附件本地路劲
    public attachmentIdForWorkTicket: string = null; // 工作票的附件id
    public twoTicketsCreatedTime: number = null; // 两票开出时间
    public inspectionRecordsSubmittedTime: number = null; // 勘察记录提交时间
    public finishedTime: number = null; // 检修完成时间
    public status: number = null;   // 检修状态（0： 待勘察，1： 待审核， 2： 待检修  3： 完成
    public record: InspectionRecords = null;
    public operationsTicket: InspectionOperationsTickets = null;
    public manuals: Array<InspectionManuals> = [];
    public workTicket: WorkTicket = null;
    public syncStatus: SyncStatus = SyncStatus.None;       // 同步状态：   （0: 从来没上传, 1: 上传成功, 2: 正在上传, 3: 上传失败)


    constructor(json: { [key: string]: any }) {
        super(json);
        InspectionTasks.mapFromJSON(json, this);
    }


}
